package org.peterf.foxish.engine.setting;

import org.peterf.foxish.engine.Engine;

import android.view.Gravity;
import android.widget.FrameLayout.LayoutParams;

/**
 * Stores screen settings which will be applied by {@link Engine}.
 * 
 * @author peter
 * 
 */
public abstract class ScreenSetting {

    /**
     * Enumeration type, can be either {@link #LANDSCAPE} or {@link #PORTRAIT}.
     * 
     * @author peter
     * 
     */
    public static enum ScreenOrientation {
        LANDSCAPE, PORTRAIT
    }

    /**
     * Enumeration type, can be either {@link #UPDATE_CONTINUOUSLY} or
     * {@link #UPDATE_WHEN_DIRTY}.
     * 
     * @author peter
     * 
     */
    public static enum UpdateStrategy {
        UPDATE_CONTINUOUSLY, UPDATE_WHEN_DIRTY
    }

    protected int[] screenSize = new int[2];

    private boolean isFullScreen = true;

    private LayoutParams layoutParams = new LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

    private ScreenOrientation orientation = ScreenOrientation.LANDSCAPE;

    private UpdateStrategy updateStrategy = UpdateStrategy.UPDATE_CONTINUOUSLY;

    public ScreenSetting() {
        layoutParams.gravity = Gravity.CENTER;
    }

    /**
     * 
     * @return The layout parameters calculated with the gravity.
     */
    public LayoutParams getLayoutParams() {
        return layoutParams;
    }

    /**
     * This is useful when the screen is to be measured. It measures the screen
     * size according to the surface type.
     * 
     * @param widthMeasureSpec
     *            The width specification from the layout manager.
     * @param heightMeasureSpec
     *            The height specification from the layout manager.
     * @return An integer vector sized 2 indicating the measured width and
     *         height.
     * @see SurfaceType
     */
    public abstract int[] getMeasuredSize(int widthMeasureSpec,
            int heightMeasureSpec);

    /**
     * 
     * @return The orientation of the screen expected.
     */
    public ScreenOrientation getOrientation() {
        return orientation;
    }

    /**
     * 
     * @return The update strategy.
     */
    public UpdateStrategy getUpdateStrategy() {
        return updateStrategy;
    }

    /**
     * 
     * @return Whether the screen is full.
     */
    public boolean isFullScreen() {
        return isFullScreen;
    }

    public float screenToStdX(float screenX) {
        return (screenX - (screenSize[0] >> 1)) / screenSize[0];
    }

    public float screenToStdY(float screenY) {
        return ((screenSize[1] >> 1) - screenY) / screenSize[1];
    }

}
